package com.holike.crm.fragment.report.employee;

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.gallopmark.recycler.adapterhelper.CommonAdapter;
import com.holike.crm.R;
import com.holike.crm.adapter.AbsFormAdapter;
import com.holike.crm.base.BaseFragment;
import com.holike.crm.base.FragmentHelper;
import com.holike.crm.bean.MonthDataBossBean;
import com.holike.crm.dialog.CalendarPickerDialog;
import com.holike.crm.dialog.LevelAreaDialog;
import com.holike.crm.dialog.MonthDataTipsDialog;
import com.holike.crm.helper.FormDataHelper;
import com.holike.crm.helper.TextSpanHelper;

import java.util.Date;
import java.util.List;

/**
 * Created by pony on 2019/10/30.
 * Version v3.0 app报表
 */
class EmployeePerformanceHelper extends FragmentHelper {

    private Callback mCallback;
    private FrameLayout mContainerLayout;
    private LevelAreaDialog mDialog;
    private String mType, mCityCode;
    private boolean mSelectDealer;  //是否选择了经销商
    private Date mStartDate, mEndDate;
    private List<Date> mSelectedDates;
    private Handler mHandler;
    private int mRoleSelectIndex = 0; //选中的角色位置

    EmployeePerformanceHelper(BaseFragment<?, ?> fragment, Callback callback) {
        super(fragment);
        this.mCallback = callback;
        fragment.setTitle(R.string.title_staff_performance);
        fragment.setRightMenu(R.string.query_date, view -> onCalendarPicker());
        mContainerLayout = obtainView(R.id.container);
        Bundle bundle = fragment.getArguments();
        if (bundle == null) {
            onFirstEntry();
        } else {
            mSelectDealer = bundle.getBoolean("selectDealer");
            mType = bundle.getString("type");
            mCityCode = bundle.getString("cityCode");
            mStartDate = (Date) bundle.getSerializable("startDate");
            mEndDate = (Date) bundle.getSerializable("endDate");
            mHandler = new Handler();
            mHandler.postDelayed(this::doRequest, 300);
        }
    }

    /*首次进入*/
    private void onFirstEntry() {
        LinearLayout contentLayout = obtainView(R.id.ll_container);
        View view = LayoutInflater.from(mContext).inflate(R.layout.include_employee_performance_main_top, contentLayout, false);
        final TextView tvSelectDealer = view.findViewById(R.id.tv_select_dealer);
        tvSelectDealer.setOnClickListener(v -> onSelectDealer(tvSelectDealer));
        contentLayout.addView(view, 1);
        View emptyView = LayoutInflater.from(mContext).inflate(R.layout.include_empty_textview, mContainerLayout, true);
        TextView tvEmpty = emptyView.findViewById(R.id.tv_empty);
        tvEmpty.setCompoundDrawablesWithIntrinsicBounds(null, ContextCompat.getDrawable(mContext, R.drawable.ic_analysis_newretail), null, null);
        tvEmpty.setText(mContext.getString(R.string.tips_employee_performance_empty));
    }

    private void onSelectDealer(final TextView tv) {
        if (mDialog == null) {
            mDialog = new LevelAreaDialog(mContext);
        }
        mDialog.setRequired(true).setOnAreaSelectListener(new LevelAreaDialog.OnAreaSelectListener() {
            @Override
            public void onAreaSelected(String name, String type, String cityCode, boolean isSelectDealer) {
                mType = type;
                mCityCode = cityCode;
                tv.setText(name);
                mSelectDealer = true;
                doRequest();
            }

            @Override
            public void onDismissDealer() {
                mFragment.showShortToast(R.string.please_select_dealer);
            }
        });
        mDialog.show();
    }

    private void onCalendarPicker() {
        new CalendarPickerDialog.Builder(mContext).maxDate(new Date())
                .withSelectedDates(mSelectedDates)
                .clickToClear(true)
                .calendarRangeSelectedListener(new CalendarPickerDialog.OnCalendarRangeSelectedListener() {
                    @Override
                    public void onLeftClicked(CalendarPickerDialog dialog) {
                    }

                    @Override
                    public void onRightClick(CalendarPickerDialog dialog, List<Date> selectedDates, Date start, Date end) {
                        mSelectedDates = selectedDates;
                        if (selectedDates.size() >= 1) {
                            mStartDate = start;
                            mEndDate = end;
                        } else {
                            mStartDate = null;
                            mEndDate = null;
                        }
                        dialog.dismiss();
                        if (mSelectDealer) {
                            doRequest();
                        }
                    }
                }).show();
    }

    void doRequest() {
        mCallback.doRequest(mType, mCityCode, mStartDate, mEndDate);
    }

    void onSuccess(MonthDataBossBean bean) {
        String isShop = bean.isShop;
        mContainerLayout.removeAllViews();
        if (!TextUtils.equals(isShop, "1") && !TextUtils.equals(isShop, "2") && !TextUtils.equals(isShop, "3")) {
            LayoutInflater.from(mContext).inflate(R.layout.include_empty_textview, mContainerLayout, true);
        } else {
            requestUpdate(isShop, bean);
        }
    }

    private void requestUpdate(String isShop, MonthDataBossBean bean) {
        if (TextUtils.equals(isShop, "1")) {
            View container = LayoutInflater.from(mContext).inflate(R.layout.include_employee_performance_main, mContainerLayout, true);
            setDatetime(container.findViewById(R.id.tv_time), bean);
            setDescription(container.findViewById(R.id.tv_description));
            FrameLayout contentLayout = container.findViewById(R.id.fl_content_layout);
            LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) contentLayout.getLayoutParams();
            params.leftMargin = mContext.getResources().getDimensionPixelSize(R.dimen.dp_10);
            View root = LayoutInflater.from(mContext).inflate(R.layout.include_form_data_content, contentLayout, true);
            bindShopType(root, bean);
        } else if (TextUtils.equals(isShop, "2")) { //员工数据
            View container = LayoutInflater.from(mContext).inflate(R.layout.include_employee_performance_child, mContainerLayout, true);
            setDatetime(container.findViewById(R.id.tv_time), bean);
            setDescription(container.findViewById(R.id.tv_description));
            setShopDetail(container.findViewById(R.id.tv_shop_detail), bean);
            FrameLayout contentLayout = container.findViewById(R.id.fl_content_layout);
            List<MonthDataBossBean.ArrBean2> list = bean.getArr2();
            LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) contentLayout.getLayoutParams();
            params.leftMargin = mContext.getResources().getDimensionPixelSize(R.dimen.dp_10);
            View root = LayoutInflater.from(mContext).inflate(R.layout.include_employee_performance_child_content, contentLayout, true);
            final RecyclerView rvRole = root.findViewById(R.id.rv_role);
            rvRole.setLayoutManager(new LinearLayoutManager(mContext, RecyclerView.HORIZONTAL, false));
            final RoleListAdapter adapter = new RoleListAdapter(mContext, list, mRoleSelectIndex);
            rvRole.setAdapter(adapter);
            adapter.setOnItemClickListener((a, holder, view, position) -> {
                mRoleSelectIndex = position;
                adapter.setSelectIndex(position);
                rvRole.smoothScrollToPosition(position);
                switchRole(root, position, list);
            });
            switchRole(root, mRoleSelectIndex, list);
        } else { //员工收款数据
            View container = LayoutInflater.from(mContext).inflate(R.layout.include_employee_performance_receipt, mContainerLayout, true);
            setDatetime(container.findViewById(R.id.tv_time), bean);
            setShopDetail(container.findViewById(R.id.tv_shop_detail), bean);
            String name = mContext.getString(R.string.customer_name_tips);
            if (!TextUtils.isEmpty(bean.userName)) {
                name += bean.userName;
            }
            ((TextView) container.findViewById(R.id.tv_name)).setText(name);
            FrameLayout contentLayout = container.findViewById(R.id.fl_content_layout);
            LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) contentLayout.getLayoutParams();
            params.leftMargin = mContext.getResources().getDimensionPixelSize(R.dimen.dp_10);
            View root = LayoutInflater.from(mContext).inflate(R.layout.include_form_data_content, contentLayout, true);
            bindCollectionType(root, bean);
        }
    }

    private void setDatetime(TextView tv, MonthDataBossBean bean) {
        tv.setText(bean.timeDetail);
    }

    private void setDescription(TextView tv) {
        tv.setOnClickListener(view -> new MonthDataTipsDialog(mContext).show());
    }

    private void setShopDetail(TextView tv, MonthDataBossBean bean) {
        tv.setText(bean.shopDetail);
    }

    private void bindShopType(View root, MonthDataBossBean bean) {
        FormDataHelper.attachView(root, new FormDataHelper.FormDataBinder() {
            @Override
            public int bindFirstColumnLayoutRes() {
                return R.layout.include_form_data_column_60dp;
            }

            @Override
            public CharSequence bindSideTitle() {
                return mContext.getString(R.string.report_table_divide);
            }

            @Override
            public int bindFirstRowLayoutRes() {
                return R.layout.include_monthdata_boss_tablist;
            }

            @Override
            public RecyclerView.Adapter bindSideAdapter() {
                return new ShopFormAdapter(mContext, bean.getArr(), true);
            }

            @Override
            public RecyclerView.Adapter bindContentAdapter() {
                return new ShopFormAdapter(mContext, bean.getArr(), false);
            }
        }, new FormDataHelper.SimpleFormDataCallback() {
            @Override
            public void bindFirstRow(View view) {
                TextView tvInstallArea = view.findViewById(R.id.tv_install_area);
                tvInstallArea.setText(TextSpanHelper.getSquareMeter(tvInstallArea.getText().toString()));
            }
        });
    }

    private void switchRole(View rootView, int position, List<MonthDataBossBean.ArrBean2> list) {
        if (position < 0 || position >= list.size()) return;
        MonthDataBossBean.ArrBean2 bean = list.get(position);
        //1导购 2业务员 3设计师 4 安装工 5管理员
        if (!TextUtils.equals(bean.type, "1") && !TextUtils.equals(bean.type, "2")
                && !TextUtils.equals(bean.type, "3") && !TextUtils.equals(bean.type, "4")
                && !TextUtils.equals(bean.type, "5")) {
            return;
        }
        final int firstColumnLayoutId;
        final int firstRowLayoutId;
        RecyclerView.Adapter<?> sideAdapter;
        RecyclerView.Adapter<?> contentAdapter;
        if (TextUtils.equals(bean.type, "4")) {
            firstColumnLayoutId = R.layout.include_form_data_column_80dp;
        } else {
            firstColumnLayoutId = R.layout.include_form_data_column_60dp;
        }
        if (TextUtils.equals(bean.type, "1") || TextUtils.equals(bean.type, "2")) {
            firstRowLayoutId = R.layout.include_monthdata_boss_tablist2;
            sideAdapter = new GuideSalesmanFormAdapter(mContext, bean.getList(), true);
            contentAdapter = new GuideSalesmanFormAdapter(mContext, bean.getList(), false);
        } else if (TextUtils.equals(bean.type, "3")) {
            firstRowLayoutId = R.layout.include_monthdata_boss_tablist3;
            sideAdapter = new DesignerFormAdapter(mContext, bean.getList(), true);
            contentAdapter = new DesignerFormAdapter(mContext, bean.getList(), false);
        } else if (TextUtils.equals(bean.type, "4")) {
            firstRowLayoutId = R.layout.include_monthdata_boss_tablist4;
            sideAdapter = new InstallerFormAdapter(mContext, bean.getList(), true);
            contentAdapter = new InstallerFormAdapter(mContext, bean.getList(), false);
        } else {
            firstRowLayoutId = R.layout.include_monthdata_boss_tablist5;
            sideAdapter = new ManagerFormAdapter(mContext, bean.getList(), true);
            contentAdapter = new ManagerFormAdapter(mContext, bean.getList(), false);
        }
        FormDataHelper.attachView(rootView, new FormDataHelper.FormDataBinder() {
            @Override
            public int bindFirstColumnLayoutRes() {
                return firstColumnLayoutId;
            }

            @Override
            public CharSequence bindSideTitle() {
                return mContext.getString(R.string.division);
            }

            @Override
            public int bindFirstRowLayoutRes() {
                return firstRowLayoutId;
            }

            @Override
            public RecyclerView.Adapter bindSideAdapter() {
                return sideAdapter;
            }

            @Override
            public RecyclerView.Adapter bindContentAdapter() {
                return contentAdapter;
            }
        }, new FormDataHelper.SimpleFormDataCallback() {
            @Override
            public void bindFirstRow(View view) {
                if (TextUtils.equals(bean.type, "4")) {
                    TextView tvInstallArea = view.findViewById(R.id.tv_install_area);
                    tvInstallArea.setText(TextSpanHelper.getSquareMeter(tvInstallArea.getText().toString()));
                }
            }
        });
    }

    private void bindCollectionType(View root, MonthDataBossBean bean) {
        FormDataHelper.attachView(root, new FormDataHelper.FormDataBinder() {
            @Override
            public int bindFirstColumnLayoutRes() {
                return R.layout.include_form_data_column_80dp;
            }

            @Override
            public CharSequence bindSideTitle() {
                return mContext.getString(R.string.tips_customer_name);
            }

            @Override
            public int bindFirstRowLayoutRes() {
                return R.layout.include_monthdata_boss_tablowest;
            }

            @Override
            public RecyclerView.Adapter bindSideAdapter() {
                return new CollectionFormAdapter(mContext, bean.getArr3(), true);
            }

            @Override
            public RecyclerView.Adapter bindContentAdapter() {
                return new CollectionFormAdapter(mContext, bean.getArr3(), false);
            }
        });
    }

    class ShopFormAdapter extends AbsFormAdapter<MonthDataBossBean.ArrBean> {

        private int mLayoutResourceId;
        private boolean mSide;

        ShopFormAdapter(Context context, List<MonthDataBossBean.ArrBean> dataList, boolean isSide) {
            super(context, dataList);
            mSide = isSide;
            mLayoutResourceId = mSide ? R.layout.item_month_data_boss_side : R.layout.item_month_data_boss_content;
        }

        @Override
        protected void bindViewHolder(RecyclerHolder holder, MonthDataBossBean.ArrBean bean, int position) {
            holder.setText(R.id.tv_division, bean.area); //划分
            setClickableCell(holder, position, R.id.tv_division, mSide && bean.isClickable(), view -> startFragment(bean.type, bean.cityCode));
            holder.setText(R.id.tv_principal, bean.name); //名字
            holder.setText(R.id.tv_new_customers, bean.newCount); //新建客户数
            holder.setText(R.id.tv_number_calls, bean.conversation); //通话次数
            holder.setText(R.id.tv_number_scale, bean.prescaleCount); //预约量尺数
            holder.setText(R.id.tv_number_measure, bean.scaleCount); //量尺数
            holder.setText(R.id.tv_number_drawing, bean.picCount); //出图数
            holder.setText(R.id.tv_deposit_customers, bean.ordersCustomer); //订单客户数
            holder.setText(R.id.tv_signatures, bean.contractCount); //签约数
            holder.setText(R.id.tv_order_number, bean.orders); //下单数
            holder.setText(R.id.tv_number_install, bean.installed); //安装数
            holder.setText(R.id.tv_install_area, bean.are); //安装平方数
            holder.setText(R.id.tv_complete_rate, bean.firstSuccess); //一次安装完成率
            holder.setText(R.id.tv_number_highSeas, bean.seaCustomer); //公海客户数
            holder.setText(R.id.tv_received, bean.receivables); //已收款
            setClickableCell(holder, position, R.id.tv_received, !mSide && bean.isClickable2(), view -> startFragment(bean.type, bean.cityCode));
            holder.setText(R.id.tv_contract_amount, bean.contractTotal); //成交总金额
        }

        @Override
        protected int bindView(int viewType) {
            return mLayoutResourceId;
        }
    }

    /*角色列表适配器*/
    class RoleListAdapter extends CommonAdapter<MonthDataBossBean.ArrBean2> {

        int mSelectIndex;

        RoleListAdapter(Context context, List<MonthDataBossBean.ArrBean2> mDatas, int selectIndex) {
            super(context, mDatas);
            mSelectIndex = selectIndex;
        }

        void setSelectIndex(int selectIndex) {
            this.mSelectIndex = selectIndex;
            notifyDataSetChanged();
        }

        @Override
        protected int bindView(int viewType) {
            return R.layout.item_form_data_tabhost;
        }

        @Override
        public void onBindHolder(RecyclerHolder holder, MonthDataBossBean.ArrBean2 bean, int position) {
            if (mSelectIndex == position) {
                holder.setTextColorRes(R.id.tv_role, R.color.color_while);
                holder.itemView.setBackgroundResource(R.drawable.bg_corners5dp_top_coloraccent);
            } else {
                holder.setTextColorRes(R.id.tv_role, R.color.textColor5);
                holder.itemView.setBackgroundResource(R.drawable.bg_corners5dp_top_bg);
            }
            holder.setText(R.id.tv_role, bean.tag);
        }
    }

    /*导购、业务员*/
    class GuideSalesmanFormAdapter extends AbsFormAdapter<MonthDataBossBean.ArrBean> {
        private int mLayoutResourceId;
        private boolean mSide;

        GuideSalesmanFormAdapter(Context context, List<MonthDataBossBean.ArrBean> dataList, boolean isSide) {
            super(context, dataList);
            mSide = isSide;
            mLayoutResourceId = mSide ? R.layout.item_month_data_guidesalesman_side : R.layout.item_month_data_guidesalesman_content;
        }

        @Override
        protected void bindViewHolder(RecyclerHolder holder, MonthDataBossBean.ArrBean bean, int position) {
            holder.setText(R.id.tv_principal, bean.name);
            holder.setText(R.id.tv_new_customers, bean.newCount); //新建客户数
            holder.setText(R.id.tv_number_calls, bean.conversation); //通话次数
            holder.setText(R.id.tv_number_scale, bean.prescaleCount); //预约量尺数
            holder.setText(R.id.tv_deposit_customers, bean.ordersCustomer); //订单客户数
            holder.setText(R.id.tv_signatures, bean.contractCount); //签约数
            holder.setText(R.id.tv_number_highSeas, bean.seaCustomer); //公海客户数
            holder.setText(R.id.tv_received, bean.receivables); //已收款
            holder.setText(R.id.tv_contract_amount, bean.contractTotal); //成交总金额
            setClickableCell(holder, position, R.id.tv_received, !mSide && bean.isClickable2(), view -> startFragment(bean.type, bean.cityCode));
        }

        @Override
        protected int bindView(int i) {
            return mLayoutResourceId;
        }
    }

    /*设计师*/
    class DesignerFormAdapter extends AbsFormAdapter<MonthDataBossBean.ArrBean> {
        private int mLayoutResourceId;
        private boolean mSide;

        DesignerFormAdapter(Context context, List<MonthDataBossBean.ArrBean> dataList, boolean isSide) {
            super(context, dataList);
            mSide = isSide;
            mLayoutResourceId = mSide ? R.layout.item_month_data_designer_side : R.layout.item_month_data_designer_content;
        }

        @Override
        protected void bindViewHolder(RecyclerHolder holder, MonthDataBossBean.ArrBean bean, int position) {
            holder.setText(R.id.tv_principal, bean.name);
            holder.setText(R.id.tv_number_calls, bean.conversation); //通话次数
            holder.setText(R.id.tv_number_measure, bean.scaleCount); //量尺数
            holder.setText(R.id.tv_number_drawing, bean.picCount); //出图数
            holder.setText(R.id.tv_signatures, bean.contractCount); //签约数
            holder.setText(R.id.tv_order_number, bean.orders); //下单数
            holder.setText(R.id.tv_number_highSeas, bean.seaCustomer); //公海客户数
            holder.setText(R.id.tv_received, bean.receivables); //已收款
            setClickableCell(holder, position, R.id.tv_received, !mSide && bean.isClickable2(), view -> startFragment(bean.type, bean.cityCode));
            holder.setText(R.id.tv_contract_amount, bean.contractTotal); //成交总金额
        }

        @Override
        protected int bindView(int i) {
            return mLayoutResourceId;
        }
    }

    /*安装工数据*/
    class InstallerFormAdapter extends AbsFormAdapter<MonthDataBossBean.ArrBean> {
        private int mLayoutResourceId;

        InstallerFormAdapter(Context context, List<MonthDataBossBean.ArrBean> dataList, boolean isSide) {
            super(context, dataList);
            mLayoutResourceId = isSide ? R.layout.item_month_data_installer_side : R.layout.item_month_data_installer_content;
        }

        @Override
        protected void bindViewHolder(RecyclerHolder holder, MonthDataBossBean.ArrBean bean, int position) {
            holder.setText(R.id.tv_principal, bean.name);
            holder.setText(R.id.tv_install_count, bean.installed); //安装数
            holder.setText(R.id.tv_install_area, bean.are); //安装平方数
            holder.setText(R.id.tv_complete_rate, bean.firstSuccess); //一次安装完成率
        }

        @Override
        protected int bindView(int i) {
            return mLayoutResourceId;
        }
    }

    /*管理者数据*/
    class ManagerFormAdapter extends AbsFormAdapter<MonthDataBossBean.ArrBean> {

        private int mLayoutResourceId;
        private boolean mSide;

        ManagerFormAdapter(Context context, List<MonthDataBossBean.ArrBean> dataList, boolean isSide) {
            super(context, dataList);
            mSide = isSide;
            mLayoutResourceId = mSide ? R.layout.item_month_data_manager_side : R.layout.item_month_data_manager_content;
        }

        @Override
        protected void bindViewHolder(RecyclerHolder holder, MonthDataBossBean.ArrBean bean, int position) {
            holder.setText(R.id.tv_principal, bean.name);
            holder.setText(R.id.tv_new_customers, bean.newCount); //新建客户数
            holder.setText(R.id.tv_number_calls, bean.conversation); //通话次数
            holder.setText(R.id.tv_number_scale, bean.prescaleCount); //预约量尺数
            holder.setText(R.id.tv_deposit_customers, bean.ordersCustomer); //订单客户数
            holder.setText(R.id.tv_signatures, bean.contractCount); //签约数
            holder.setText(R.id.tv_received, bean.receivables); //已收款
            setClickableCell(holder, position, R.id.tv_received, !mSide && bean.isClickable2(), view -> startFragment(bean.type, bean.cityCode));
            holder.setText(R.id.tv_contract_amount, bean.contractTotal); //成交总金额
        }

        @Override
        protected int bindView(int i) {
            return mLayoutResourceId;
        }
    }

    /*收款数据*/
    private final class CollectionFormAdapter extends AbsFormAdapter<MonthDataBossBean.ArrBean3> {

        private int mResourceLayoutId;

        CollectionFormAdapter(Context context, List<MonthDataBossBean.ArrBean3> dataList, boolean isSide) {
            super(context, dataList);
            mResourceLayoutId = isSide ? R.layout.item_month_data_single_side : R.layout.item_month_data_single_content;
        }

        @Override
        protected void bindViewHolder(RecyclerHolder holder, MonthDataBossBean.ArrBean3 bean, int position) {
            holder.setText(R.id.tv_customer_name, bean.name);
            holder.setText(R.id.tv_receipt_category, bean.type);//收款类型
            holder.setText(R.id.tv_receipt_amount, bean.money); //收款金额
            holder.setText(R.id.tv_receipt_time, bean.payTime);//收款时间
        }

        @Override
        protected int bindView(int viewType) {
            return mResourceLayoutId;
        }
    }

    private void startFragment(String type, String cityCode) {
        Bundle bundle = new Bundle();
        bundle.putBoolean("selectDealer", mSelectDealer);
        bundle.putString("type", type);
        bundle.putString("cityCode", cityCode);
        bundle.putSerializable("startDate", mStartDate);
        bundle.putSerializable("endDate", mEndDate);
        mFragment.startFragment(new EmployeePerformanceFragment(), bundle, true);
    }

    void onFailure(String failReason) {
        mContainerLayout.removeAllViews();
        View view = LayoutInflater.from(mContext).inflate(R.layout.include_empty_page, mContainerLayout, true);
        view.findViewById(R.id.ll_empty_page).setBackgroundResource(R.color.color_while);
        mFragment.noNetwork(failReason);
    }

    interface Callback {
        void doRequest(String type, String cityCode, Date startDate, Date endDate);
    }

    void onDestroy() {
        if (mDialog != null) {
            mDialog.dismiss();
        }
        if (mHandler != null) {
            mHandler.removeCallbacksAndMessages(null);
        }
    }
}
